package ${cfg.parentPackageServer}.impl.consumer;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import ${cfg.parentPackage}.entity.${entity};
import ${cfg.parentPackage}.dto.${entity}DTO;
import ${cfg.parentPackage}.vo.${entity}VO;
import ${package.Mapper}.${table.mapperName};
import ${cfg.parentPackageServer}.consumer.U${table.serviceName};

import com.lplb.common.core.result.R;
import com.lplb.common.core.result.RType;
import com.lplb.common.core.service.BaseIServiceImpl;
import com.lplb.common.core.utils.BeanDtoVoUtil;
import com.lplb.common.coreconfig.config.ErrorException;
import org.apache.commons.lang3.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
/**
 * <p>
 * ${table.comment!} 用户端服务接口实现
 * </p>
 *
 * @author ${author}
 * @date ${date}
 */
@RestController
public class U${table.serviceImplName}  extends BaseIServiceImpl<${table.mapperName}, ${entity}> implements U${table.serviceName} {


         /**
         *  分页查询
         */
         @Override
         public R<IPage<${entity}VO>> findPage() {
             Page<${entity}> page = this.page(this.getPage(), new LambdaQueryWrapper<${entity}>()
                     .orderByAsc(${entity}::getCreateTime)
             );
             return R.success(BeanDtoVoUtil.pageVo(page, ${entity}VO.class));
         }

        /**
        *  查询所有
        */
        @Override
        public R<List<${entity}VO>> findList() {
              List<${entity}> list = this.list(new LambdaQueryWrapper<${entity}>()
                      .orderByAsc(${entity}::getCreateTime)
              );
              return R.success(BeanDtoVoUtil.listVo(list, ${entity}VO.class));
        }

        /**
        * ID 查询
        *
        * @return
        */
        @Override
        public R<${entity}VO> findId(@RequestParam String id) {
            ${entity} ${entity?uncap_first} = this.getById(id);
            return R.success(BeanDtoVoUtil.convert(${entity?uncap_first},${entity}VO.class));
        }


        /**
        * 新增
        */
        @Override
        public R<Void> add(@RequestBody @Validated ${entity}DTO dto) {
            this.save(dto.convert(${entity}.class));
            return R.success();
        }


        /**
        *  编辑
        */
        @Override
        public R<Void> upd(@RequestBody @Validated ${entity}DTO dto) {
            this.updateById(dto.convert(${entity}.class));
            return R.success();
        }


        /**
        *  ID 删除
        */
        @Override
        public R<Void> removeId(@RequestParam String id) {
            this.removeById(id);
            return R.success();
        }

 }

